package io.mft.datasource.mq.rabbitmq.producer;



import java.util.concurrent.ExecutorService;

import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.PublisherCallbackChannel;
import org.springframework.amqp.rabbit.connection.PublisherCallbackChannelFactory;
import org.springframework.amqp.rabbit.connection.PublisherCallbackChannelImpl;

import com.rabbitmq.client.Channel;

import io.mft.datasource.mq.rabbitmq.MqDatasource;

/**
 * @说明： TODO
 * @类型名称：MqConnectionFactory
 * @创建者 ： 杨亮
 * @创建时间： 2019/11/5  14:31
 * @修改者 ： 杨亮
 * @修改时间： 2019/11/5  14:31
 */
public class MqProducerConnectionFactory  extends CachingConnectionFactory {

    public MqProducerConnectionFactory( MqDatasource datasource){
        super();
        this.setAddresses( datasource.getAddresses() );
        this.setUsername(  datasource.getUsername() );
        this.setPassword(  datasource.getPassword()  );
        this.setVirtualHost(datasource.getVirtualHost());
        this.setPublisherConfirms(true);
        this.setPublisherReturns(true);
        this.setPublisherChannelFactory( new PublisherCallbackChannelFactory(){
            public PublisherCallbackChannel createChannel(Channel delegate, ExecutorService executor) {
                return new PublisherCallbackChannelImpl( delegate , executor );
            }
        });
        this.setChannelCacheSize(datasource.getChannel());
    }

}
